package com.example.littleSpider.myapplication.activity;

import android.content.Intent;
import android.graphics.Color;
import android.support.design.widget.BottomSheetDialog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

import com.example.littleSpider.myapplication.R;
import com.example.littleSpider.myapplication.base.BaseActivity;
import com.example.littleSpider.myapplication.myInterfaces.MethodInTitle;
import com.example.littleSpider.myapplication.view.TitleView;
import com.littlespider.mylibrary.util.T;
import com.weigan.loopview.LoopView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import es.dmoral.toasty.Toasty;

/**
 * Created by EDZ on 2017/12/12.
 * 我要发单界面
 */

public class SendActivity extends BaseActivity implements MethodInTitle, View.OnClickListener {

    @BindView(R.id.title_view)
    TitleView mTitleView;
    @BindView(R.id.checkbox_confirmed)
    CheckBox checkbox_confirmed;
    @BindView(R.id.btn_mysend)
    Button btn_mysend;
    @BindView(R.id.tv_type)
    TextView tv_type;
    private BottomSheetDialog dialog;
    //    LoopView loopView = new LoopView(this);
    LoopView loopView;


    @Override
    protected int getLayoutRes() {
        return R.layout.activity_send;
    }

    @Override
    protected void initView() {
        Log.i("little", "xiaoheshang");
        mTitleView.initMyTitle("我要发单", this);
        mTitleView.showRightTwo(false);
        mTitleView.hideTitleTextImage();


    }

    //各条目点击事件
    @OnClick({R.id.layout_origin,
            R.id.layout_end,
            R.id.layout_goodstype,
            R.id.layout_pointCourier,
            R.id.checkbox_confirmed,
            R.id.tv_agreement,
            R.id.tv_inform,
            R.id.btn_mysend})

    public void sendInfoClik(View view) {
        switch (view.getId()) {
            case R.id.layout_origin:
                Toasty.success(this, "填写寄件人信息").show();
                startActivity(new Intent(this, SendInfoActivity.class));
                break;
            case R.id.layout_end:
                Toasty.success(this, "填写收件人信息").show();
                startActivity(new Intent(this, EndInfoActivity.class));
                break;
            case R.id.layout_goodstype:
                openBottomItemType();
                break;
            case R.id.layout_pointCourier:
                Toasty.success(this, "指定派送员").show();
                openBottomDriver();
                break;
            case R.id.checkbox_confirmed:
                if (checkbox_confirmed.isChecked()) {
                    btn_mysend.setEnabled(true);

                } else {
                    btn_mysend.setEnabled(false);
                }
                break;
            case R.id.btn_mysend:
                //TODO 发单成功

                break;
            //跳转webview
            case R.id.tv_agreement:
                Toasty.success(this, "服务协议").show();
                startActivity(new Intent(this, AgreementActivity.class));
                break;
            case R.id.tv_inform:
                Toasty.success(this, "物品告知").show();
                startActivity(new Intent(this, InFormActivity.class));
                break;

        }
    }

    /**
     * 从底部弹出的指定司机选择dialog
     */

    private void openBottomDriver() {
        dialog = new BottomSheetDialog(this);
        dialog.setContentView(R.layout.bottom_itemdriver);

        List<String> items = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            items.add("张老三" + i);
        }
        loopView = (LoopView) dialog.findViewById(R.id.loop_view_driver);
        loopView.setNotLoop();
        loopView.setItems(items);
        loopView.setCenterTextColor(Color.BLUE);
        loopView.setTextSize(20);

        loopView.setInitPosition(0);

        dialog.show();

    }

    /**
     * 从底部弹出的物品类型选择dialog
     */
    private void openBottomItemType() {

        dialog = new BottomSheetDialog(this);
        dialog.setContentView(R.layout.bottom_itemtype);
        dialog.show();

        TextView tv_cancel = (TextView) dialog.findViewById(R.id.tv_cancel);
        TextView tv_confirm = (TextView) dialog.findViewById(R.id.tv_confirm);

        TextView tv_other = (TextView) dialog.findViewById(R.id.tv_other);
        TextView tv_package = (TextView) dialog.findViewById(R.id.tv_package);
        TextView tv_clothing = (TextView) dialog.findViewById(R.id.tv_clothing);

        TextView tv_food = (TextView) dialog.findViewById(R.id.tv_food);
        TextView tv_appliance = (TextView) dialog.findViewById(R.id.tv_appliance);
        TextView tv_furniture = (TextView) dialog.findViewById(R.id.tv_furniture);

        TextView tv_hardware = (TextView) dialog.findViewById(R.id.tv_hardware);
        TextView tv_commodity = (TextView) dialog.findViewById(R.id.tv_commodity);
        TextView tv_material = (TextView) dialog.findViewById(R.id.tv_material);


        tv_cancel.setOnClickListener(this);
        tv_confirm.setOnClickListener(this);

        tv_other.setOnClickListener(this);
        tv_package.setOnClickListener(this);
        tv_clothing.setOnClickListener(this);
        tv_food.setOnClickListener(this);
        tv_appliance.setOnClickListener(this);
        tv_furniture.setOnClickListener(this);
        tv_hardware.setOnClickListener(this);
        tv_commodity.setOnClickListener(this);
        tv_material.setOnClickListener(this);

    }

    @Override
    protected void initData() {

    }

    @Override
    public void setGoBack() {
        Toasty.success(this, "finish").show();
        finish();
    }

    @Override
    public void onRightOne() {

    }

    @Override
    public void onRightTwo() {

    }

    @Override
    public void onTitleText() {

    }

    /**
     * @param view
     */
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_cancel:
                dialog.dismiss();
                T.show(this, "取消");
                break;
            case R.id.tv_confirm:
                dialog.dismiss();
                T.show(this, "确定");
                break;
            case R.id.tv_other:
                dialog.dismiss();
                tv_type.setText("其他");
                T.show(this, "其他");
                break;
            case R.id.tv_package:
                dialog.dismiss();
                tv_type.setText("快递包裹");
                T.show(this, "快递包裹");
                break;

            case R.id.tv_clothing:
                dialog.dismiss();
                tv_type.setText("服装鞋帽");
                T.show(this, "服装鞋帽");
                break;

            case R.id.tv_food:
                dialog.dismiss();
                tv_type.setText("食品");
                T.show(this, "食品");
                break;

            case R.id.tv_appliance:
                dialog.dismiss();
                tv_type.setText("家电");
                T.show(this, "家电");
                break;

            case R.id.tv_furniture:
                dialog.dismiss();
                tv_type.setText("家居");
                T.show(this, "家居");
                break;

            case R.id.tv_hardware:
                dialog.dismiss();
                tv_type.setText("五金");
                T.show(this, "五金");
                break;

            case R.id.tv_commodity:
                dialog.dismiss();
                tv_type.setText("百货");
                T.show(this, "百货");
                break;

            case R.id.tv_material:
                dialog.dismiss();
                tv_type.setText("建材");
                T.show(this, "建材");
                break;
        }
    }
}
